package com.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.codec.binary.Base64;

public class ApplicationUtils {

	private static final String HASH_ALGORITHM = "SHA-256";
	
	public static String createTimeStamp() {
		SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmmss");
		Date today = Calendar.getInstance().getTime();
		return sdf.format(today);
	}

//	public static void main(String[] args) {
//		SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmmss");
//		Date today = Calendar.getInstance().getTime();
//		System.out.println(sdf.format(today));
//	}
	
	public static String dateToString(Date date){
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		return sdf.format(date);
	}
	public static String securePassword(String plainText) throws Exception{
		String str="";
		try {
			MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
			md.update(plainText.getBytes("UTF-8"));
			byte raw[] = md.digest();
			str= new String(Base64.encodeBase64(raw));
		} catch (NoSuchAlgorithmException e) {
			throw new Exception(e.getMessage());
		} catch (UnsupportedEncodingException e) {
			throw new Exception(e.getMessage());
		}
		return str;
	}
	public static void main(String[] args) {
		try {
			System.out.println(securePassword("Anu"));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
